<template>
  <div>
    <el-card>
      <h1>通过网页上传单词</h1>
      <el-form >
        <el-form-item label="单词">
          <el-input v-model="inputWord.word" placeholder="请在此输入单词"></el-input>
        </el-form-item>
        <el-form-item label="假名">
          <el-input v-model="inputWord.kana" placeholder="请在此输入假名"></el-input>
        </el-form-item>
        <el-form-item label="中文">
          <el-input v-model="inputWord.chinese" placeholder="请在此输入中文"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" @click="webAdding()">上传</el-button>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      inputWord: {
        userId: 0,
        word: '',
        kana: '',
        chinese: '',
      },
    }
  },

  methods: {
    async webAdding() {
      this.inputWord.userId = window.localStorage.getItem('userId');
      let result = await this.$API.word.addWordByWeb(this.inputWord);
      if (result.code == 200) {
        this.$message({
          message: "单词上传成功！",
          type: "success",
        });
        this.inputWord.word = '';
        this.inputWord.kana = '';
        this.inputWord.chinese = '';
      } else {
        this.$message({
          message: res.msg,
          type: "error",
        });
      }
    },
  }
}
</script>

<style>

</style>